from django.db import models
from user.models import User, Company
from software.models import SoftwareVersion, SoftwareGroup
from storehouse.models import Storehouse


# Create your models here.

class Store(models.Model):
    STORESTATE = (
        (0, u'已启用'),
        (1, u'已禁用'),
    )
    software = models.ForeignKey(
        SoftwareVersion,
        verbose_name=u"软件",
        on_delete=models.CASCADE,
        related_name='software_commidity',
        null=True
    )
    softwareGroup = models.ForeignKey(
        SoftwareGroup,
        verbose_name=u"软件编组",
        on_delete=models.CASCADE,
        related_name='software_group',
    )
    user = models.ForeignKey(
        User,
        verbose_name=u"用户",
        on_delete=models.CASCADE,
        related_name='store_user',
    )
    storehouse = models.ForeignKey(
        Storehouse,
        verbose_name=u"仓库",
        on_delete=models.CASCADE,
        related_name='storehouse_store',
        null=True
    )
    company = models.ForeignKey(
        Company,
        verbose_name=u'所属单位',
        on_delete=models.CASCADE,
        related_name='store_company',
        null=True
    )
    storeName = models.CharField(
        verbose_name=u'商店名称',
        max_length=20,
        default=u'',
    )
    storeState = models.CharField(
        choices=STORESTATE,
        max_length=50,
        default=u'',
        verbose_name=u"商店状态",
    )
    isRunning = models.BooleanField(
        default=True,
        verbose_name=u'是否运行',
    )
    isConnecting = models.BooleanField(
        default=True,
        verbose_name=u'是否接入',
    )
    storehouseIP = models.GenericIPAddressField(
        verbose_name=u'接入仓库IP地址',
        default=u'',
    )
    storeIP = models.GenericIPAddressField(
        verbose_name=u'商店IP地址',
        default=u'',
    )
    applyTime = models.DateTimeField(
        verbose_name=u"申请时间",
        null=True
    )
    createTime = models.DateTimeField(
        auto_now_add=True,
        verbose_name=u"创建时间",
    )
    isActive = models.BooleanField(
        verbose_name=u'是否活跃',
        default=True,
    )

    def __unicode__(self):
        return self.createTime

    class Meta:
        ordering = ('createTime',)
